﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Activities;
using System.Web.Mvc;

using NUnit.Framework;

using Microsoft.Practices.Unity;

using ERPStore.Extensions;

namespace ERPStore.Indexers.Tests
{
	[TestFixture]
	public class CatalogServiceTest : ERPStore.Tests.TestBase
	{
		[SetUp]
		public override void Initialize()
		{
			base.Initialize();

			var settings = GlobalConfiguration.Configuration.DependencyResolver.GetService<ERPStore.Indexers.Lucene.Models.Settings>();

			// Création de l'index
			var parameters = new Dictionary<string, object>();
			parameters.Add("PageSize", 100);
			parameters.Add("IndexPath", settings.Path);
			parameters.Add("WorkingFolder", "Catalog");

			var wi = new WorkflowInvoker(new ERPStore.Indexers.Lucene.Workflows.BuildFullTextIndexWorkflow());
			wi.Invoke(parameters);
		}


		[Test]
		public void Simple_Search()
		{
			var connectorService = GlobalConfiguration.Configuration.DependencyResolver.GetService<ERPStore.Services.IConnectorService>();
			connectorService.RegisterCatalogService();
			var catalogService = GlobalConfiguration.Configuration.DependencyResolver.GetService<ERPStore.Services.ICatalogService>();

			var search = "xbox";
			var filter = new Models.ProductListFilter()
			{
				Search = search,
			};
			var count = 0;
			var result = catalogService.GetProductListBySearch(filter,0,int.MaxValue, out count);

			Assert.Greater(result.Count, 0);
		}

		[Test]
		public void Search_With_Category()
		{
			var connectorService = GlobalConfiguration.Configuration.DependencyResolver.GetService<ERPStore.Services.IConnectorService>();
			connectorService.RegisterCatalogService();
			var catalogService = GlobalConfiguration.Configuration.DependencyResolver.GetService<ERPStore.Services.ICatalogService>();

			var filter = new Models.ProductListFilter()
			{
				ProductCategoryId = 1,
			};
			var count = 0;
			var result = catalogService.GetProductListBySearch(filter, 0, int.MaxValue, out count);

			Assert.Greater(result.Count, 0);
		}

		[Test]
		public void Search_With_Brand()
		{
			var connectorService = GlobalConfiguration.Configuration.DependencyResolver.GetService<ERPStore.Services.IConnectorService>();
			connectorService.RegisterCatalogService();
			var catalogService = GlobalConfiguration.Configuration.DependencyResolver.GetService<ERPStore.Services.ICatalogService>();

			var filter = new Models.ProductListFilter()
			{
				BrandId = 1,
			};
			var count = 0;
			var result = catalogService.GetProductListBySearch(filter, 0, int.MaxValue, out count);

			Assert.Greater(result.Count, 0);
		}


	}
}
